library(DBI)
library(RMySQL)

# --------------- Master data
#		Populate MIDI note dimension
pop.midi.note <- function() {
	midi_notes <- seq(0,127)
	notes<-seq(0,11)
	octaves<-floor((midi_notes - 24)/12)
	cat(paste("INSERT INTO midi_note (midi_note_id,note_id,octave) VALUES (",midi_note[,1],",",midi_note[,2],",",midi_note[,3],");",sep=""),sep="\n")	
}

#---- Connection and fetching
getConnection <- function() {
	dbConnect(MySQL(), user="root", password="root", dbname="klavier", host="localhost")
}

fetchTable <- function(tableName) {
	con <- getConnection()
	data <- dbReadTable(con,tableName)
	dbDisconnect(con)
	return(data)
}

fetchResult <- function(query) {
	con <- getConnection()
	rs <- dbSendQuery(con, query)
	data <- fetch(rs, n = -1)
	dbDisconnect(con)
	return(data)
}
